package cn.com.open.itembank.dto;

import cn.com.open.itembank.common.GlobalConst;

/**
 * Created by lucky on 2017/11/3.
 */
public class DeleteListResult {
    private Integer successCount;
    private Integer noExistCount;
    private Integer failedCount;

    /**
     * Instantiates a new Delete list result.
     */
    public DeleteListResult() {
        successCount = 0;
        noExistCount = 0;
        failedCount = 0;
    }

    /**
     * Gets result.
     *
     * @param result the result
     */
    public void getResult(ReturnModel result) {
        if (result.getCode() == GlobalConst.SUCCESS) {
            successCount++;
        } else if (result.getCode() == GlobalConst.ID_NOT_EXIST || result.getCode() == GlobalConst.QUESTION_ITEM_BANK_NOT_MATCH) {
            noExistCount++;
        } else {
            failedCount++;
        }
    }

    /**
     * Gets message.
     *
     * @param type the type
     * @return the message
     */
    public String getMessage(String type) {
        String executeResult = "执行结果：";

        StringBuilder message = new StringBuilder(executeResult);
        if (successCount > 0) {
            message.append(String.format("%s %d 道试题成功；", type, successCount));
        }
        if (noExistCount > 0) {
            message.append(String.format("%s %d 道试题ID不存在；", type, noExistCount));
        }
        if (noExistCount > 0) {
            message.append(String.format("%s %d 道试题失败；", type, failedCount));
        }

        return message.toString();
    }
}
